package com.action;


import java.io.IOException;
import java.io.PrintWriter;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.bean.*;
import com.service.*;
public class manageraction extends ActionSupport{
	private Manager manager;
	private managerService<Manager> ms;
	
	public String ManagerLogin(){
		try {
			manager = ms.ManagerLogin(manager.getName(), manager.getPwd());
			ServletActionContext.getRequest().getSession().setAttribute("admin",manager);
			ServletActionContext.getRequest().getSession().setMaxInactiveInterval(60*60*12);
			return SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			try {
				
				PrintWriter out = ServletActionContext.getResponse().getWriter();
				out.print("<script>alert('Entered Incorrectlymis-typed')</script>");
				out.print("<script>history.go(-1)</script>");
				out.flush();
				out.close();
				
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			return null;
		}	
		
	}
	
	public String MgPwdEdit(){
		try {
			ms.MgPwdEdit(manager);
			
			PrintWriter out = ServletActionContext.getResponse().getWriter();
			out.print("<script>alert('Modify Successfully')</script>");
			out.print("<script>history.go(-1)</script>");
			out.flush();
			out.close();
			return null;
	
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public String AddMg(){
		try {
			
				ms.AddMg(manager);
				PrintWriter out = ServletActionContext.getResponse().getWriter();
				out.print("<script>alert('Add Manager Successfully')</script>");
				out.print("<script>history.go(-1)</script>");
				out.flush();
				out.close();
				return null;
			}
				
		catch (Exception e) {
			// TODO Auto-generated catch block			
			try {
				PrintWriter out = ServletActionContext.getResponse().getWriter();
				out.print("<script>alert('The Manager Account has existed already')</script>");
				out.print("<script>history.go(-1)</script>");
				out.flush();
				out.close();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
			e.printStackTrace();
		}
		return null;
	}
	
	

	public Manager getManager() {
		return manager;
	}

	public void setManager(Manager manager) {
		this.manager = manager;
	}

	public managerService<Manager> getMs() {
		return ms;
	}

	public void setMs(managerService<Manager> ms) {
		this.ms = ms;
	}
	

}